/* 作者：邓伟，网站：https://mqtt.vb6.pro */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  line-height: 1.6;
  background-color: #f0f2f5;
  position: relative;
  height: 100vh;
  overflow: hidden;
}

.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 4px;
  color: white;
  font-size: 14px;
  z-index: 9000;
  animation: fadeInOut 0.3s ease-in-out;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.toast.info {
  background-color: #0084ff;
}

.toast.success {
  background-color: #28a745;
}

.toast.error {
  background-color: #dc3545;
}

.toast.warning {
  background-color: #ffc107;
  color: #333;
}

@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: white;
  padding: 10px 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
}

.main-container {
  display: flex;
  padding: 100px 20px 20px;
  gap: 20px;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
}

.server-info {
  overflow: auto;
  flex: 0 0 300px;
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  height: calc(100vh - 120px);
}

.chat-container {
  flex: 1;
  height: calc(100vh - 120px);
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
}

.info-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.info-item:hover {
  background: #e9ecef;
}

.info-item .label {
  /* display: block; */
  color: #666;
  font-size: 0.9em;
  margin-bottom: 4px;
}

.info-item .value {
  color: #333;
  font-weight: 500;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 100%;
}

.message-wrapper.received {
  align-self: flex-start;
  margin-right: 64px;
}

.message-wrapper.sent {
  flex-direction: row-reverse;
  align-self: flex-end;
  margin-left: 64px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}

.message-content {
  position: relative;
  padding: 12px 16px;
  border-radius: 12px;
  max-width: 100%;
  width: fit-content; /* 让宽度适应内容 */
}

.message-content pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  margin: 0;
}

.received .message-content {
  background-color: #f1f0f0;
  border-top-left-radius: 4px;
}

.received .message-content::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 14px;
  border-width: 6px;
  border-style: solid;
  border-color: transparent #f1f0f0 transparent transparent;
}

.sent .message-content {
  background-color: #0084ff;
  color: white;
  border-top-right-radius: 4px;
}

.sent .message-content::before {
  content: "";
  position: absolute;
  right: -8px;
  top: 14px;
  border-width: 6px;
  border-style: solid;
  border-color: transparent transparent transparent #0084ff;
}

.input-container {
  padding: 20px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 10px;
}

.input-container input,
.input-container textarea {
  flex: 1;
  padding: 0px;
  border: 0;
  border-radius: 4px;
  outline: none;
}

.input-container button {
  padding: 10px 20px;
  background: #0084ff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.input-container button:hover {
  background: #0073e6;
}

.topic-input {
  margin: 20px 0;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 4px;
}

.topic-input .label {
  display: block;
  color: #666;
  font-size: 0.9em;
  margin-bottom: 8px;
}

.topic-input input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  outline: none;
}

.topic-input input:disabled {
  background-color: #e9ecef;
  cursor: not-allowed;
}

.connect-btn {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 4px;
  background-color: #0084ff;
  color: white;
  cursor: pointer;
  transition: background-color 0.2s;
  margin-bottom: 20px;
}

.connect-btn:hover {
  background-color: #0073e6;
}

.connect-btn.connected {
  background-color: #dc3545;
}

.connect-btn.connected:hover {
  background-color: #c82333;
}

.connection-status {
  padding: 10px;
  border-radius: 4px;
  text-align: center;
  background-color: #dc3545;
  color: white;
}

.connection-status.connected {
  background-color: #28a745;
}

.warning-block {
  background-color: #fff3cd;
  border: 1px solid #ffeeba;
  color: #856404;
  padding: 10px;
  margin-top: 15px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.5;
}

.warning-block a {
  color: #856404;
  text-decoration: underline;
}

.warning-block a:hover {
  color: #533f03;
  text-decoration: none;
}

.info-block {
  background-color: #cccccc;
  border: 1px solid #bbbbbb;
  /* color: #856404; */
  padding: 10px;
  margin-top: 15px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.5;
}

.text-center {
  text-align: center;
}

.message-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start; /* 让内容区域不跟随信息区域的宽度 */
}

.sent .message-block {
  align-items: flex-end; /* 发送的消息靠右对齐 */
}

.message-info {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: #666;
  padding: 0 4px; /* 添加一些内边距 */
}

.sender-id {
  font-weight: 500;
}

.message-time {
  color: #999;
}

.sent .message-info {
  flex-direction: row-reverse;
}

.sent .sender-id {
  color: #0084ff;
}

/* 主题切换相关样式 */
:root {
  --bg-color: #f0f2f5;
  --card-bg: #fff;
  --text-color: #333;
  --text-secondary: #666;
  --text-tertiary: #999;
  --message-sent-bg: #0084ff;
  --message-sent-color: #fff;
  --message-received-bg: #f1f0f0;
  --message-received-color: #333;
  --border-color: #eee;
  --hover-bg: #e9ecef;
  --info-item-bg: #f8f9fa;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --deep-color: #000;
}

[data-theme="dark"] {
  --bg-color: #1a1a1a;
  --card-bg: #2d2d2d;
  --text-color: #e0e0e0;
  --text-secondary: #a0a0a0;
  --text-tertiary: #808080;
  --message-sent-bg: #0084ff;
  --message-sent-color: #fff;
  --message-received-bg: #3a3a3a;
  --message-received-color: #e0e0e0;
  --border-color: #404040;
  --hover-bg: #363636;
  --info-item-bg: #363636;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --deep-color: #fff;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
}

.header {
  position: fixed;
  top: 20px;
  left: 0;
  right: 0;
  background: var(--card-bg);
  padding: 10px 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1360px;
  margin: auto;
  border-bottom: 1px solid var(--border-color);
  border-radius: 8px;
}

.title-row {
  flex: 1;
}

.title-row h2 {
  margin: 0;
  color: var(--text-color);
  font-size: 1.5em;
}

.controls-row {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.control-btn {
  width: 40px;
  height: 40px;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  color: var(--text-color);
}

.control-btn .theme {
  filter: drop-shadow(2px 4px 6px var(--deep-color));
}

.control-btn:hover {
  background-color: var(--hover-bg);
  transform: translateY(-1px);
}

.control-btn.muted {
  color: var(--text-tertiary);
}

.control-btn img,
.control-btn svg {
  width: 24px;
  height: 24px;
}

.theme-toggle {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.theme-toggle:hover {
  background-color: var(--hover-bg);
}

.theme-toggle img {
  width: 24px;
  height: 24px;
  color: var(--text-color);
}

.server-info,
.chat-container {
  background: var(--card-bg);
  box-shadow: 0 2px 4px var(--shadow-color);
}

.server-info h2 {
  color: var(--text-color);
}

.info-item {
  background: var(--info-item-bg);
}

.info-item:hover {
  background: var(--hover-bg);
}

.info-item .label {
  color: var(--text-secondary);
}

.info-item .value {
  color: var(--text-color);
}

.message-content {
  color: var(--text-color);
}

.received .message-content {
  background-color: var(--message-received-bg);
  color: var(--message-received-color);
}

.sent .message-content {
  background-color: var(--message-sent-bg);
  color: var(--message-sent-color);
}

.received .message-content::before {
  border-color: transparent var(--message-received-bg) transparent transparent;
}

.sent .message-content::before {
  border-color: transparent transparent transparent var(--message-sent-bg);
}

.input-container {
  border-top-color: var(--border-color);
}

.input-container input {
  background: var(--card-bg);
  color: var(--text-color);
  /* border: 1px solid var(--border-color); */
}

.input-container button {
  background: var(--message-sent-bg);
  color: var(--message-sent-color);
  border: none;
}

.warning-block {
  background-color: var(--info-item-bg);
  border-color: var(--border-color);
}

/* 订阅人数显示样式 */
.subscribers-info {
  margin-top: 15px;
  background: var(--card-bg) !important;
  border: 1px solid var(--border-color);
}

.subscribers-info .value {
  font-size: 1.1em;
  font-weight: bold;
  color: var(--message-sent-bg);
}

/* 折叠面板样式 */
.collapsible-panel {
  margin-bottom: 15px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--info-item-bg);
  cursor: pointer;
  transition: background-color 0.2s;
}

.panel-header:hover {
  background: var(--hover-bg);
}

.panel-header .chevron-icon {
  transition: transform 0.3s ease;
}

.panel-header.expanded .chevron-icon {
  transform: rotate(180deg);
}

.panel-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}

.panel-content.expanded {
  max-height: 500px;
  transition: max-height 0.5s ease-in;
}

.panel-content .info-item {
  margin: 0;
  border-radius: 0;
}

.panel-content .info-item:not(:last-child) {
  border-bottom: 1px solid var(--border-color);
}

/* 头部控制区样式 */
.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sound-toggle {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
  color: var(--text-color);
}

.sound-toggle:hover {
  background-color: var(--hover-bg);
}

.sound-toggle.muted {
  color: var(--text-tertiary);
}

/* 平滑过渡效果 */
body * {
  transition: background-color 0.3s, color 0.3s, border-color 0.3s,
    box-shadow 0.3s;
}

/* 响应式布局样式 */
@media screen and (max-width: 768px) {
  .container {
    flex-direction: column;
    margin: 0;
    height: 100vh;
    gap: 10px;
    padding: 10px;
  }

  .title-icon {
    margin-right: 0 !important;
  }

  .server-info {
    flex: 0 0 auto;
    /* max-height: 40vh; */
    padding: 15px;
  }

  .server-info h2 {
    margin-bottom: 15px;
    font-size: 18px;
  }

  .info-item {
    margin-bottom: 10px;
    padding: 8px;
    font-size: 14px;
  }

  .chat-container {
    flex: 1;
    min-height: 0;
  }

  .messages {
    padding: 10px;
    gap: 12px;
  }

  .message-wrapper.received {
    margin-right: 40px;
  }

  .message-wrapper.sent {
    margin-left: 40px;
  }

  .message-content {
    padding: 8px 12px;
    max-width: calc(100vw - 120px);
  }

  .input-container {
    padding: 10px;
  }

  .input-container input {
    flex: 1;
    min-width: 0;
    padding: 8px;
  }

  .input-container button {
    padding: 8px 16px;
    white-space: nowrap;
  }

  .avatar {
    width: 32px;
    height: 32px;
  }

  .warning-block {
    font-size: 12px;
    padding: 10px;
    margin: 10px 0;
  }

  .message-info {
    font-size: 11px;
  }

  .toast {
    width: calc(100% - 32px);
    /* margin: 0 16px; */
    font-size: 13px;
  }
}

/* 超小屏幕设备的额外优化 */
@media screen and (max-width: 480px) {
  /* .server-info {
    max-height: 25vh;
  } */

  .message-wrapper.received {
    margin-right: 20px;
  }

  .message-wrapper.sent {
    margin-left: 20px;
  }

  .message-content {
    max-width: calc(100vw - 80px);
  }

  .container {
    padding: 5px;
    gap: 5px;
  }
}

.sidebar-toggle {
  display: none;
}

.sidebar-overlay {
  display: none;
}

@media (max-width: 768px) {
  .header {
    top: 0;
    border-radius: 0;
  }

  .main-container {
    padding: 0;
    margin-top: 60px;
  }

  .server-info {
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    width: 280px;
    margin: 0;
    border-radius: 0;
    height: calc(100vh - 60px);
    transition: transform 0.3s ease;
    z-index: 1500;
  }

  .server-info.visible {
    transform: translateX(0);
  }

  .chat-container {
    margin-left: 0;
    height: calc(100vh - 60px);
    border-radius: 0;
  }

  .sidebar-toggle {
    display: block;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 800;
  }

  .sidebar-overlay.visible {
    display: block;
  }
}

/* Dark mode styles */
.dark-mode .header {
  background: #1e1e1e;
  border-bottom: 1px solid #333;
}

.dark-mode .server-info,
.dark-mode .chat-container {
  background: #1e1e1e;
  border: 1px solid #333;
}

.title-icon {
  width: 24px;
  height: 24px;
  vertical-align: middle;
  margin-right: 8px;
  margin-top: -3px;
}
